package demo2String;

import org.junit.Test;

import java.lang.reflect.Array;

/**
 * @ClassName $ {NAME}
 * @Description TODO
 * @Author shenxinyuan
 * @Date $ {DATE} $ {TIME}
 * @Version 1. 0
 **/

public class ReverseWordOrder {

    String str = "nowcoder. a am I";

    public String ReverseSentence(String str) {
        String res = "";
        String temp = "";
        char[] chars = str.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == ' ') {
                res = " "+temp + res;
                temp = "";
            }else {
                temp = temp + chars[i];
            }

            if (chars.length - 1 ==i) {
                res = temp +res;
            }
        }
        return res;
    }

    @Test
    public void test() {
        System.out.println("ReverseSentence(str) = " + ReverseSentence(str));
        System.out.println("ReverseSentence(str) = " + ReverseSentence(str).length());
    }
}
